#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 2000 + 10;

int n, L, v[N][N], sum, tot, p[N];
bool vis[N];
pair < ll, ll > pos[N][N], ans[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, L = in;
	rep(i, 1, n) {
		tot = sum = 0;
		rep(j, 1, L) tot += (v[i][j] = in);
		int cur = 1;
		rep(j, 1, n - 1) {
			while(cur <= L && 1ll * n * (v[i][cur] + sum) <= 1ll * tot * j) sum += v[i][cur++];
			pos[i][j].fi = 1ll * j * tot - 1ll * n * sum + 1ll * (cur - 1) * v[i][cur] * n;
			pos[i][j].se = 1ll * v[i][cur] * n;
			//cerr << i << " " << j << " " << pos[i][j].fi << " " << pos[i][j].se << endl;
			ll d = __gcd(pos[i][j].fi, pos[i][j].se);
			pos[i][j].fi /= d; pos[i][j].se /= d;
		}
	}
	rep(i, 1, n) {
		int x = 0;
		rep(y, 1, n) if(!vis[y]) {
			if(x == 0) x = y;
			else if((db)pos[y][i].fi / pos[y][i].se <= (db)pos[x][i].fi / pos[x][i].se) x = y;
		}
		vis[x] = true; ans[i] = pos[x][i]; p[i] = x;
	} rep(i, 1, n - 1) printf("%lld %lld\n", ans[i].fi, ans[i].se);
	rep(i, 1, n) printf("%d ", p[i]); puts("");
	return 0;
}
